package gam.n1.areas.impl.a.config;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import gam.n1.areas.Area;
import gam.n1.areas.impl.a.DefaultDefendVArea;
import gam.n1.conf.i.AreaConfig;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class DefendVConfig extends AreaConfig {

    public DefendVConfig(@NotNull Plugin plugin, @NotNull String filePath) {
        super(plugin, filePath);
    }

    @Override
    protected Area pC(Area area, Map map) {
        if (area instanceof DefaultDefendVArea){
            Set<Location> vl = tl((List) map.get("vl"));
            Set<Location> pl = tl((List) map.get("pl"));
            Set<Location> ml = tl((List) map.get("ml"));
            if (vl.size() > 0 && pl.size() > 0 && ml.size() > 0){
                ((DefaultDefendVArea) area).reborn(pl);
                ((DefaultDefendVArea) area).vol(vl);
                ((DefaultDefendVArea) area).por(ml);
            }
            return area;
        }
        return null;
    }
    private Set<Location> tl(List l){
        Set<Location> t = Sets.newHashSet();
        for (Object o : l) {
            Map o1 = (Map) o;
            String w = (String) o1.get("world");
            double x = (double) o1.get("x");
            double y = ((double) o1.get("y"));
            double z = ((double) o1.get("z"));
            t.add(new Location(Bukkit.getWorld(w),x,y,z,0,0));
        }
        return t;
    }
}
